package com.redis;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Set;

/**
 * @Date 2022/9/16 10:44
 * @Author WangLinBao
 * @Description
 */
@RestController
public class RedisController {

    @Autowired
    private RedisTemplate redisTemplate;
    public static final String PREFIX_SUBSCRIBE = ":subscribe";

    @GetMapping("/addSubscribe")
    public String addSubscribe(Integer userId,Integer subscribeUserId){
        redisTemplate.opsForSet().add(userId+PREFIX_SUBSCRIBE,subscribeUserId);
        return "success";
    }
    @GetMapping("/getCommonSubscribe")
    public String getCommonSubscribe(Integer userId,Integer subscribeUserId){
        Set intersect = redisTemplate.opsForSet().intersect(userId + PREFIX_SUBSCRIBE, subscribeUserId + PREFIX_SUBSCRIBE);
        return intersect.toString();
    }


}
